This disclosure relates generally to optimize Java 7 and more specifically to optimize the performance of method handles in Java 7.
In computer programming, an application programming interface (API) is a set of routines, protocols, and tools for building software applications. An API expresses a software component in terms of its operations, inputs, outputs, and underlying types. An API defines functionalities that are independent of their respective implementations, which allows definitions and implementations to vary without compromising each other. A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together.
Method handles were introduced into the Java® (Java is a registered trademark of Oracle Corp.) language API with Java 7.0. A method handle is a typed, directly executable reference to an underlying method, constructor, field, or similar low-level operation, with optional transformations of arguments or return values. These transformations are quite general, and include such patterns as conversion, insertion, deletion, and substitution. Such method handle commands allow developers to write a program that includes a call to a function that is not present when the program is initially compiled. The method handles look up the functions at run time, based on the name of the called function.
Included in the method handle API is the guard with test command. Guard with test functions as an if-statement. For example, the command: “MethodHandles.guardwithtest(MethodHandle test, MethodHandle target, MethodHandle fallback)” would execute method handle target if method handle test returned true, and would execute method handle fallback if method handle test returned false.